/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.unindra.raport.dao.impl;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import edu.unindra.raport.dao.entity.User;
import edu.unindra.raport.dao.interf.UserInterf;
import edu.unindra.raport.dao.koneksi.DatabaseUtilities;

/**
 * 
 * @author fendi
 */
public class UserImpl implements UserInterf {

	public void insert(User user) throws SQLException {
		PreparedStatement ps = null;
		try {
			ps = DatabaseUtilities.getInstance().getConnection()
					.prepareStatement("insert into user values (?,?)");
		} catch (Exception e) {
			e.printStackTrace();
		}
		ps.setString(1, user.getNama());
		ps.setString(2, user.getPassword());
		ps.executeUpdate();
	}

	public User getUser() throws SQLException {
		Statement st = null;
		try {
			st = DatabaseUtilities.getInstance().getConnection()
					.createStatement();
		} catch (Exception e) {
			e.printStackTrace();
		}
		ResultSet rs = st.executeQuery("select *from user");
		User us = new User();
		while (rs.next()) {
			us.setNama(rs.getString("nama"));
			us.setPassword(rs.getString("password"));
		}
		return us;
	}

}
